<template>
	<view v-if="content" class="unread">
		<view class="unread-view">
			{{displayValue()}}
		</view>
	</view>
</template>

<script setup>
	/**
	 * @property {String} content 角标内容
	 * @property {Number} maxNum 展示封顶的数字值，超过 9 显示 9+
	 */
	import {
		computed
	} from 'vue';

	const props = defineProps({
		content: {
			type: [String, Number],
			default: ""
		},
		maxNum: {
			type: Number,
			default: 9
		}
	});

	function displayValue() {
		return Number(props.content) > props.maxNum ? `${props.maxNum}+` : props.content
	}
</script>

<style lang="scss">
	.unread {
		position: relative;
	}

	.unread-view {
		display: flex;
		height: 32rpx;
		color: white;
		align-items: center;
		justify-content: center;
		position: absolute;
		background: red;
		right: 0rpx;
		padding: 0rpx 10rpx;
		transform: translate(25%, -25%);
		border-radius: 16rpx;
		overflow: hidden;
		min-width: 32rpx;
		font-size: 20rpx;
	}
</style>